using System.Collections.Generic;
using NDomain.Reflection;

namespace NDomain.Reflection
{
    public class FactoryProcessor : BaseClassProcessor
    {
        public override void Process(IClassInfoProvider clazz, IDomainInfo domainInfo)
        {
            IDictionary<string, IAttributeInfoProvider> attributes = AttributesAsDictionary(clazz.GetAttributes());

            if (!attributes.ContainsKey(typeof (FactoryAttribute).FullName)) return;

            DelayProcessing(
                delegate
                    {
                        domainInfo.NewFactory(clazz.GetNamespace(), clazz.GetName(),
                                              (string)
                                              attributes[typeof (FactoryAttribute).FullName].GetPropertyValue("Entity"));
                    });
        }
    }
}